﻿Imports Microsoft.Reporting.WinForms
Imports System.IO
Imports System.Windows.Forms
Imports System.Reflection

Public Class relRotulo
#Region " Campos de instância "
   Private dsRelatorio As DataSet
#End Region
#Region "Propriedades"
    ''' <summary>
    ''' Propriedade pública que recebe os dados do Relatorio.
    ''' </summary>    
    Property pDtsRelatorio As DataSet
        Get
            Return dsRelatorio
        End Get
        Set(ByVal value As DataSet)
            dsRelatorio = value
        End Set
    End Property

#End Region
#Region " Métodos Privados "
    Private Sub relUsuariosCourier_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'Variavel para alimentar o dataSource do report
        Dim rdsRotulo As ReportDataSource = New ReportDataSource()

        'Alimenta dataSource

        rdsRotulo.Value = dsRelatorio.Tables(0)
        rdsRotulo.Name = "dtsRotulo"

        'Informa ao Report que ele utilizar 
        Me.rptRelatorio.LocalReport.DataSources.Add(rdsRotulo)

        'Exportar apenas para PDF.
        eliminarExportacao()

        'Carrega Relatorio
        Me.rptRelatorio.RefreshReport()
    End Sub

    ''' <summary>
    ''' Método responsável por desabilitar a exportação do relatório para Word e Excel.
    ''' </summary>
    Public Sub eliminarExportacao()
        Dim renFormato As RenderingExtension
        Dim lRelatorio As LocalReport
        lRelatorio = rptRelatorio.LocalReport
        For Each renFormato In lRelatorio.ListRenderingExtensions
            If Trim(renFormato.LocalizedName) = "Excel" Or Trim(renFormato.LocalizedName) = "Word" Then
                Dim info As FieldInfo = renFormato.GetType().GetField("m_isVisible", BindingFlags.NonPublic Or BindingFlags.Instance)
                info.SetValue(renFormato, False)
            End If
        Next
    End Sub
#End Region
End Class